// 点击输入请购单号
var $$scope;
var $CertusFormAjax;
var $CertusJsonAjax;
var $fileListService;
function addNo() {
    layer.prompt({
        title: '请输入请购单号，并确认！',
        formType: 3
    }, function (text, index) {
        //去检查是否有还没有完全走完的请购单
        $CertusFormAjax.ajax("examinePurchaseStatus",{"purchaseNo":text},function(res){
            if(res.data == "success"){
                layer.close(index);
                layer.msg('请购单号：' + text+",正在为您跳转比价单添加页面。");
                location.href='#/addSupplier/'+text;
            }else if (res.data == "purchaseError"){
                layer.msg("当前请购单不可用");
            }else{
                layer.msg("当前请购单还有比价流程正在审批中,请稍后再提。")
            }
        })

    });
}

// 点击输入请购单号
function addNoed() {
    layer.prompt({
        title: '请输入请购单号，并确认！',
        formType: 3
    }, function (text, index) {
        layer.close(index);
        layer.msg('请购单号：' + text+",正在为您跳转比价单添加页面。");
        location.href='#/addSuppliered/'+text;
    });
}
var dataInitHistory = null;
// 报价历史库展示隐藏效果
function shadbox(biCode,commodityClassCode) {

    // $CertusFormAjax.ajax("findHistoryQuote", {biCode: biCode, commodityClassCode: commodityClassCode}, function (res) {
    //     middleGrid.exhibitDatas = res.data;
    //     middleGrid.refresh(false);
    //     $(".hdplog").show();
    // })

    if(dataInitHistory == null){
        dataInitHistory = $CertusJsonAjax.dataInit('findHistoryQuote',{biCode: biCode, commodityClassCode: commodityClassCode},pricelogColumns,'pricelogContainer','pricelogToolBarContainer');
    }else{
        dataInitHistory.parameters = {biCode: biCode, commodityClassCode: commodityClassCode};
        dataInitHistory.refresh(true);
    }
    var status = $(".shadbox").css('display');
    if (status == "none") {
        $(".shadbox").show();
        var boxId = "#shadbox";
        // toBox(boxId);
    } else {
        $(".shadbox").hide();
    }
}

// 页面定位效果
function toBox(id) {
    $(id)[0].scrollIntoView();
}

// 上传文件展示隐藏效果
function shuplod(bqCode,biCode) {
    $$scope.nowUploadBqcode = bqCode;
    $$scope.nowUploadBicode = biCode;

    initFileUpload($$scope, fileInstantiation, fileInstantiationDisable, $CertusFormAjax);
    var status = $(".shuplod").css('display');
    if (status == "none") {
        $(".shuplod").show();
        var boxId = "#shuplod";
        toBox(boxId);
    } else {
        $(".shuplod").hide();
    }
}



// 文件上传-选择密级显示隐藏效果
$(function () {
    $(".filetype").change(function () {
        if ($(this).val() == 1) {
            $(".fileun").show();
        } else {
            $(".fileun").hide();
        }
    })
});

// 请购清单
var purchaselistColumns = [{
    id: 'proList',
    title: '类目',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'proType',
    title: '类别',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'proName',
    title: '名称',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'spec',
    title: '品名及规格',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'number',
    title: '数量',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'price',
    title: '单价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'sum',
    title: '总价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'message',
    title: '备注',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'operation',
    title: '操作',
    width: 350,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        content += '<button class="btn btn-xs btn-primary" onclick="shadbox()"><i class="icon-eye-open"></i>  报价历史库</button>';
        content += '  ';
        content += '<button class="btn btn-xs btn-info"><i class="icon-eye-open"></i>  查看供应商报价</button>';
        content += '  ';
        content += '<button class="btn btn-xs btn-success" onclick="shpriceox();"><i class="icon-plus"></i>  添加供应商报价</button>';
        return content;
    }
}, ];


function shpriceoxBidCode(bqCode,brCode) {

    if (bqCode && brCode) {
        var bqArray2 = bqArray[brCode];
        for (var i in bqArray2) {
            if (bqArray2[i].bqCode == bqCode) {
                $$scope.buyingQuoteItem = bqArray2[i];
                $$scope.$apply();
            }
        }
    }
    var status = $(".shpriceox").css('display');
    if (status == "none") {
        $(".shpriceox").show();
        layer.msg("添加供应商信息后，才能够上传《报价文件》");
        var boxId = "#shpriceox";
        toBox(boxId);

        var listString = "报价信息";
        for (var i = 0; i < checkValue.length + 1; i++) {
            listString += "【" + checkValue[i].proList + "-" + checkValue[i].proType + "-" + checkValue[i].proName + "】";
            $("#prcmsg").val(listString);
        }

    } else {
        $(".shpriceox").hide();
        layer.msg("请记得上传附件《报价文件》");
    }
}

// 供应商报价展示隐藏效果
function shpriceox(biCode) {

    var exhibitDatas = aboveGrid.exhibitDatas;
    for (var i in exhibitDatas) {
        if (exhibitDatas[i].biCode == biCode) {
            var insertTemp = exhibitDatas[i];
            $$scope.buyingQuoteItem = {};
            $$scope.buyingQuoteItem = {
                "commodityCateName": insertTemp.commodityCateName,
                "commodityClassName": insertTemp.commodityClassName,
                "commodityClassCode": insertTemp.commodityClassCode,
                "name": insertTemp.name,
                "descAndSpec": insertTemp.descAndSpec,
                "biCode": insertTemp.biCode,
                "brCode": insertTemp.brCode,
                "bqCode": "Bq-" + new Date().getTime() + Math.floor(Math.random() * 10000)
            }
            $$scope.$apply();
        }
    }
    var status = $(".shpriceox").css('display');
    if (status == "none") {
        $(".shpriceox").show();
        layer.msg("添加供应商信息后，才能够上传《报价文件》");
        var boxId = "#shpriceox";
        toBox(boxId);

        var listString = "报价信息";
        for (var i = 0; i < checkValue.length + 1; i++) {
            listString += "【" + checkValue[i].proList + "-" + checkValue[i].proType + "-" + checkValue[i].proName + "】";
            $("#prcmsg").val(listString);
        }

    } else {
        $(".shpriceox").hide();
        layer.msg("请记得上传附件《报价文件》");
    }
}

// 请购清单
var plistogColumns = [{
    id: 'proList',
    title: '类目',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'proType',
    title: '类别',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
}, {
    id: 'proName',
    title: '名称',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'spec',
    title: '品名及规格',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'number',
    title: '数量',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'price',
    title: '单价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'sum',
    title: '总价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'message',
    title: '备注',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'operation',
    title: '操作',
    width: 110,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        // content += '<button class="btn btn-xs btn-primary" onclick="shadbox();"><i class="icon-eye-open"></i>  历史库报价</button>';
        // content += '  ';
        content += '<button class="btn btn-xs btn-info"><i class="icon-eye-open"></i>  供应商报价</button>';
        return content;
    }
}, ];


// 点击查看相关条目的供应商报价信息
function selpc() {
    layer.msg("查看相关的供应商报价信息");
}

// 报价列表-历史记录
var pricelogColumns = [{
        id: 'ptime',
        title: '报价日期',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
    }, {
        id: 'pname',
        title: '采购物资名称',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
    }, {
        id: 'prdmsg',
        title: '规格和参数',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'oneprice',
        title: '单价',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'name',
        title: '供应商名称',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'address',
        title: '地点',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'tell',
        title: '联系方式',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'tnumber',
        title: '数量',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'price',
        title: '总价(含税&折扣)',
        type: 'string',
        hideType: 'lg|md|sm|xs',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'msg',
        title: '备注说明',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'dateOfDelivery',
        title: '交货期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'guaranteeTime',
        title: '质保期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'paytype',
        title: '付款方式',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    },
    {
        id: 'test',
        title: '优劣势',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'operation',
        title: '操作',
        width: 60,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '';
            content += '<button class="btn btn-xs btn-info" data-toggle="modal" href="#myModal"><i class="icon-cloud-download"></i>  报价单</button>';
            return content;
        }
    },
];


// 报价列表-历史记录
var pricetlogColumns = [{
        id: 'pname',
        title: '采购物资名称',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
    }, {
        id: 'name',
        title: '供应商名称',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
    }, {
        id: 'address',
        title: '地点',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'tell',
        title: '联系方式',
        type: 'string',
        width: 110,
        columnClass: 'text-center',
    }, {
        id: 'tnumber',
        title: '数量',
        type: 'string',
        width: 75,
        columnClass: 'text-center',
    }, {
        id: 'oneprice',
        title: '单价',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'price',
        title: '总价(含税&折扣)',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'msg',
        title: '备注说明',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'prdmsg',
        title: '规格和参数',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'dateOfDelivery',
        title: '交货期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'guaranteeTime',
        title: '质保期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'paytype',
        title: '付款方式',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    },
    {
        id: 'test',
        title: '优劣势',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'operation',
        title: '操作',
        width: 60,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '';
            content += '<button class="btn btn-xs btn-info" data-toggle="modal" href="#myModal"><i class="icon-cloud-download"></i>  报价单</button>';
            return content;
        }
    },
];

// 供应商报价列表
var priceColumnsAdd = [{
        id: 'name',
        title: '采购物资名称',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
    }, {
        id: 'specification',
        title: '规格和参数',
        type: 'string',
        // width: 150,
        columnClass: 'text-left',
    }, {
        id: 'priceIncludingTax',
        title: '单价',
        type: 'string',
        // width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'quantity',
        title: '数量',
        type: 'string',
        // width: 100,
        columnClass: 'text-center',
    }, {
        id: 'totalPrice',
        title: '总价(含税&折扣)',
        type: 'string',
        // width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'supplierName',
        title: '供应商名称',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
    }, {
        id: 'supplierPhone',
        title: '联系方式',
        width: 110,
        columnClass: 'text-center',
    }, {
        id: 'address',
        title: '地点',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'price',
        title: '备注说明',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'dateOfDelivery',
        title: '交货期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'guaranteeTime',
        title: '质保期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'paymentMethod',
        title: '付款方式',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'strengthsAndWeaknesses',
        title: '优劣势',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    },
    {
        id: 'operation',
        title: '操作',
        width: 260,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '';
            content += '<button class="btn btn-xs btn-info" onclick="shpriceoxBidCode(\'' + record.bqCode + '\',\'' + record.biCode + '\')"><i class="fa fa-edit"></i>  编辑</button>';
            content += '  ';
            content += '<button class="btn btn-xs btn-success" onclick="shuplod(\'' + record.bqCode + '\',\'' + record.biCode + '\')"><i class="icon-cloud-upload"></i>  附件上传</button>';
            content += '  ';
            content += '<button class="btn btn-xs btn-primary" onclick="openDownloadList(\'' + record.bqCode + '\',\'' + record.biCode + '\')"><i class="icon-eye-open"></i>  附件</button>';
            content += '  ';
            content += '<button class="btn btn-xs btn-danger" onclick="del(\'' + record.bqCode + '\',\'' + record.biCode + '\');"><i class="fa fa-trash-o"></i>  删除</button>';
            return content;
        }
    },
];



// 供应商报价列表
var pricelogsColumns = [{
        id: 'name',
        title: '供应商名称',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
    }, {
        id: 'address',
        title: '地点',
        type: 'string',
        width: 100,
        columnClass: 'text-center',
    }, {
        id: 'tell',
        title: '联系方式',
        type: 'string',
        width: 110,
        columnClass: 'text-center',
    }, {
        id: 'price',
        title: '总价(含税&折扣)',
        type: 'string',
        width: 150,
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '￥' + value + '元';
            return content;
          }
    }, {
        id: 'pricemsg',
        title: '备注说明',
        type: 'string',
        columnClass: 'text-left',
    }, {
        id: 'prdmsg',
        title: '规格和参数',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'dateOfDelivery',
        title: '交货期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'guaranteeTime',
        title: '质保期',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'paytype',
        title: '付款方式',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    },
    {
        id: 'test',
        title: '优劣势',
        type: 'string',
        hideType: 'lg|md|sm|xs',
    }, {
        id: 'operation',
        title: '操作',
        width: 60,
        type: 'string',
        columnClass: 'text-center',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            var content = '';
            content += '<button class="btn btn-xs btn-primary" data-toggle="modal" href="#myModal"><i class="icon-eye-open"></i>  附件</button>';
            return content;
        }
    },
];


// 报价单列表
var supplierColumns = [{
    id: 'brCode',
    title: '请购单编号',
    width: 250,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'pcsCode',
    title: '比价单编号',
    width: 250,
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'createTime',
    title: '申请时间',
    width: 100,
    type: 'string',
    columnClass: 'text-center',
    resolution:function (value, record, column, grid, dataNo, columnNo){
        var date = new Date(record.createTime);
        var content = $.fn.dlshouwen.grid.tools.dateFormat(date, "yyyy-MM-dd hh:mm");
        return content;
    }
}, {
    id: 'purchaseMsg',
    title: '留言',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'status',
    title: '审批状态',
    type: 'string',
    width: 75,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        if(record.processEnd == 'YES'){
            return "审批完成";
        }
        return "流程进行中";
    }
}, {
    id: 'operation',
    title: '操作',
    width: 60,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        content += '<a class="btn btn-xs btn-primary" href="#/selSupplier/'+ record.pcsCode+'"><i class="icon-eye-open"></i>  查看</a>';
        return content;
    }
}];